from langchain.memory import ConversationEntityMemory
from langchain_community.llms.tongyi import Tongyi
import os

os.environ["DASHSCOPE_API_KEY"] = "sk-9d8f1914800e497f8717144e860f99bc"

llm = Tongyi()
memory = ConversationEntityMemory(llm=llm)
_input = {"input": "小明和小红是好朋友，正在一起看书"}
res1 = memory.load_memory_variables(_input)
print(res1)

# 将这段对话追加到前面缓存对话中
memory.save_context(
    _input,
    {"output": "听起来很棒，他们正在看什么书？"}
)
res2=memory.load_memory_variables({'input': '小明是谁'})
print(res2)
